//
//  ZJSCExplainView.m
//  ShangHaiHuDongApp
//
//  Created by ZJ on 2017/6/14.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ZJSCExplainView.h"

@interface ZJSCExplainView ()<ZJVoiceViewDelegate>

/** 文字内容 */
@property (nonatomic, strong) UILabel *contenLabel;
@end

@implementation ZJSCExplainView

- (instancetype)initWithFrame:(CGRect)frame title:(NSString *)title
{
    self = [super initWithFrame:frame title:title];
    if (self) {
        
        self.titleLabel.sd_layout
        .topSpaceToView(self, 15 * [UIScreen zj_screenHScale])
        .leftSpaceToView(self, 12 * [UIScreen zj_screenWScale])
        .widthIs([NSString zj_sizeOfString:title font:self.titleLabel.font width:[UIScreen zj_screenWith]].width)
        .heightIs([NSString heightWithTextFont:self.titleLabel.font]);
        [self.titleLabel updateLayout];
        
        [self addSubview:self.contenLabel];
        [self addSubview:self.voiceView];
        
        self.contenLabel.sd_layout
        .topEqualToView(self.titleLabel)
        .leftSpaceToView(self.titleLabel, 5 * [UIScreen zj_screenWScale])
        .widthIs(self.contenLabel.width)
        .heightIs(50);
        
        self.voiceView.sd_layout
        .topSpaceToView(self.contenLabel, 15 * [UIScreen zj_screenHScale])
        .leftEqualToView(self.contenLabel)
        .widthIs(90 * [UIScreen zj_screenWScale])
        .heightIs(30 * [UIScreen zj_screenHScale]);
        
        self.recordTool = [LVRecordTool sharedRecordTool];
        
    }
    return self;
}

#pragma mark - ZJVoiceViewDelegate 协议方法
- (void)ZJVoiceViewDelegate_PlayVoice{
    
    [self.recordTool playRecordingFile];
}

#pragma mark - Setter
- (void)setString:(NSString *)string{
    _string = string;
    self.contenLabel.text = string;
    
    self.contenLabel.sd_layout
    .topEqualToView(self.titleLabel)
    .leftSpaceToView(self.titleLabel, 5 * [UIScreen zj_screenWScale])
    .widthIs(self.contenLabel.width)
    .heightIs([self.contenLabel getLableSizeWithMaxWidth:self.contenLabel.width].height);
    [self.contenLabel updateLayout];
    
    self.height = self.voiceView.bottom + 15 * [UIScreen zj_screenHScale];
}

- (void)setIsHaveVideo:(BOOL)isHaveVideo{
    _isHaveVideo = isHaveVideo;
    if (isHaveVideo) {
       self.height = self.voiceView.bottom + 15 * [UIScreen zj_screenHScale];
    }else{
        self.height = self.contenLabel.bottom + 15 * [UIScreen zj_screenHScale];
    }
}

#pragma mark - Getters
- (UILabel *)contenLabel{
    if (_contenLabel == nil){
        _contenLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.titleLabel.right + 5 * [UIScreen zj_screenWScale], 0, self.width - self.titleLabel.right - (12 + 5) * [UIScreen zj_screenWScale], self.titleLabel.height)];
        _contenLabel.lineSpace = 6 * [UIScreen zj_screenHScale];
        _contenLabel.font = [UIFont titleTextFont];
        _contenLabel.characterSpace = 1;
        _contenLabel.numberOfLines = 0;
    }
    return _contenLabel;
}

- (ZJVoiceView *)voiceView{
    if (_voiceView == nil){
        _voiceView = [[ZJVoiceView alloc]initWithFrame:CGRectMake(0, 0, self.width, 30 * [UIScreen zj_screenWScale])];
        _voiceView.delegate = self;
        _voiceView.deleteButton.hidden = YES;
        _voiceView.time = @"55";
    }
    return _voiceView;
}

@end
